package cn.gson.springboot.controllers;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.spi.RegisterableService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import ch.qos.logback.core.net.SyslogOutputStream;
import cn.gson.springboot.model.dao.ChargeMoneyDAO;
import cn.gson.springboot.model.dao.LookillnessDAO;
import cn.gson.springboot.model.pojos.ApplyHospital;
import cn.gson.springboot.model.pojos.CashMoney;
import cn.gson.springboot.model.pojos.ChargeMoney;
import cn.gson.springboot.model.pojos.ClinicCard;
import cn.gson.springboot.model.pojos.InhospitalReg;
import cn.gson.springboot.model.pojos.LookIllness;
import cn.gson.springboot.model.pojos.OrderClass;
import cn.gson.springboot.model.pojos.RegistrFrom;
import cn.gson.springboot.model.pojos.RegistrType;
import cn.gson.springboot.model.pojos.Section;
import cn.gson.springboot.model.pojos.User;
import cn.gson.springboot.model.service.ApplyHosptialServices;
import cn.gson.springboot.model.service.ChargeMoneyService;
import cn.gson.springboot.model.service.ClinicCardService;
import cn.gson.springboot.model.service.DrugRoomService;
import cn.gson.springboot.model.service.DrugstorageService;
import cn.gson.springboot.model.service.HospitalprojectService;
import cn.gson.springboot.model.service.LookillnessService;
import cn.gson.springboot.model.service.RechangeService;
import cn.gson.springboot.model.service.RegistrFromService;
import cn.gson.springboot.model.service.RegistrTypeservice;
import cn.gson.springboot.model.service.SectionService;
import cn.gson.springboot.model.service.TriageService;
import cn.gson.springboot.model.service.UserService;
import cn.gson.springboot.model.vo.AdviceVo;
import cn.gson.springboot.model.vo.ChargemoneyVo;
import cn.gson.springboot.model.vo.HospitalProjectVo;
import cn.gson.springboot.model.vo.OrderClassVo;
import cn.gson.springboot.model.vo.SectionVo;
import javassist.expr.NewArray;

@Controller
@SessionAttributes({"doctersarray","resgistrarray","docnames"})
public class OutPatientController {
	
    //医疗卡的service	
	@Autowired
	private ClinicCardService  ccs;
	
	//充值service
	@Autowired
	private RechangeService res;
	
	//挂号的service
	@Autowired
	private RegistrFromService  regs;
	
	//科室service
	@Autowired
	private  SectionService ss;
	
	//挂号类型service
	@Autowired
	private RegistrTypeservice regts;
	
	//药库的药品的service
	@Autowired
	private  DrugstorageService ds ; 
	
	//住院service
	@Autowired
	private ApplyHosptialServices apps;
	
	//医疗项目service
	@Autowired
	private HospitalprojectService hs;

	//分诊service
	@Autowired
	private TriageService trs;
	
	//看诊service
	@Autowired
	private LookillnessService lookservice;
	
	//收费主表
	@Autowired
	private ChargeMoneyService chs;
	
	//入院申请
	@Autowired
	private  ApplyHosptialServices applys;
	
	//药房
	@Autowired
	private DrugRoomService drugroomservice;
	
	@Autowired
	private SectionService sectionService;
	
	//排班
	@RequestMapping("Arrange-People")
	public String  patientregist(){
		
	      return "arranges-class";
	}
	
	//科室管理
	@RequestMapping("section_manager")
	public String  section_manager(){
		
	      return "section_manage";
	}
	
	//科室管理初始化科室
	@PostMapping(value="init-section-manage")
	@ResponseBody
	 public Map<String, Object> init_section_manage(@RequestParam("page")int page,
             																						@RequestParam("rows")int rows,
             																						String section_name){
		//进行分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray selectAll_ArrangeSection = trs.selectAll_Sectionmanage(section_name);
		
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", selectAll_ArrangeSection);//封装当前页的内容

		return map;
	}
	
   //新增科室
	@PostMapping(value="add_section")
	@ResponseBody
	public  String add_section(SectionVo sectionvo) {
		
		try {
			sectionService.add_section(sectionvo);
			return "1";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "2";
		}
	}
	
	
	//排班时间初始化
	@PostMapping(value="selectarrange_time")
	@ResponseBody
	 public JSONArray selectarrange_time(){
	     JSONArray selectarrange_time = trs.selectarrange_time();
	     return selectarrange_time;
	}
	
	//查出当天排班科室
	@PostMapping(value="Present-OrderSection")
	@ResponseBody
	  public JSONArray  selectAllPresentOrderSection() {
		 try {
			JSONArray selectAll_ArrangeSection = trs.selectAll_ArrangeSection();
			 return selectAll_ArrangeSection;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	//测试排班页面
	@RequestMapping("A-testArrange")
	public void  A_testArrange(){
		
	}
	
	
	//同一个数据源查出所有排班记录
	@PostMapping(value="init-All-arrange-record")
	@ResponseBody
	  public JSONArray  init_Allarrange_record(String curdate_format) {
		 try {
			 //查询出所有科室
			JSONArray selectAll_ArrangeSection = trs.selectAll_ArrangeSection();
			JSONArray json=new JSONArray();
			for (int i = 0; i < selectAll_ArrangeSection.size(); i++) {
				//查出科室id---用于查排班人员
				JSONObject obj1=new JSONObject();
				Integer section_id=selectAll_ArrangeSection.getJSONObject(i).getInteger("section_id");
				String section_name=selectAll_ArrangeSection.getJSONObject(i).getString("section_name");
				String section_type=selectAll_ArrangeSection.getJSONObject(i).getString("section_type");
				obj1.put("section_type", section_type);
				obj1.put("section_id", section_id);
				obj1.put("section_name", section_name);
				JSONArray json1=new JSONArray();//早班医生
				JSONArray json2=new JSONArray();//早班护士
				JSONArray json3=new JSONArray();//中班医生
				JSONArray json4=new JSONArray();//中班护士
				JSONArray json5=new JSONArray();//晚班医生
				JSONArray json6=new JSONArray();//晚班护士
				
				//查询排班班次---医生
				JSONArray selectAll_arrange_classes = trs.selectAll_arrange_classes("医生","夏季");
				//医生---早班
				Integer morning_doctor_classesid=selectAll_arrange_classes.getJSONObject(0).getInteger("arrange_classsid");
				//查询医生早班人员---morning_doctor
				JSONArray selectAllPresentOrderPeople = trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
																					            null, section_id,"医生", null, null, morning_doctor_classesid);
				
				if(selectAllPresentOrderPeople.size()>0) {
					for (int j = 0; j < selectAllPresentOrderPeople.size(); j++) {
						JSONObject obj=new JSONObject();
						String  morning_doctor=selectAllPresentOrderPeople.getJSONObject(j).getString("user_name");
						obj.put("yishen", morning_doctor);
						json1.add( obj);
					}
				}
				
				//医生---中班
				Integer middle_doctor_classesid=selectAll_arrange_classes.getJSONObject(1).getInteger("arrange_classsid");
				//System.out.println("医生---中班----"+middle_doctor_classesid);
				//查询医生早班人员---morning_doctor
				JSONArray middle_doctor_OrderPeople = trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
																					            null, section_id,"医生", null, null, middle_doctor_classesid);
				//System.out.println("医中班----:"+middle_doctor_OrderPeople);
				if(middle_doctor_OrderPeople.size()>0) {
					for (int d = 0; d < middle_doctor_OrderPeople.size(); d++) {
						JSONObject obj3=new JSONObject();
						String  middle_doctor=middle_doctor_OrderPeople.getJSONObject(d).getString("user_name");
						obj3.put("yishen", middle_doctor);
						json3.add( obj3);
					}
				}
				
				//医生---晚班
				Integer night_doctor_classesid=selectAll_arrange_classes.getJSONObject(2).getInteger("arrange_classsid");
				//System.out.println("	晚班------------"+night_doctor_classesid);
				//查询医生晚班人员---morning_doctor
				JSONArray night_doctor_OrderPeople = trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
																					            null, section_id,"医生", null, null, night_doctor_classesid);
				//System.out.println("	晚班2------------"+night_doctor_OrderPeople.size());
				if(night_doctor_OrderPeople.size()>0) {
					for (int d = 0; d < night_doctor_OrderPeople.size(); d++) {
						JSONObject obj5=new JSONObject();
						String  night_doctor=night_doctor_OrderPeople.getJSONObject(d).getString("user_name");
						//System.out.println("	晚班医生------------"+night_doctor);
						obj5.put("yishen", night_doctor);
						json5.add( obj5);
					}
				}
				
				//查询排班班次---护士
				JSONArray selectAll_nurse_arrange_classes = trs.selectAll_arrange_classes("护士","夏季");
				//System.out.println("查询排班班次---护士----"+selectAll_nurse_arrange_classes);
				//护士---早班
				Integer morning_nurse_classesid=selectAll_nurse_arrange_classes.getJSONObject(0).getInteger("arrange_classsid");
				//System.out.println("查询排班班次---护士----"+morning_nurse_classesid);
				//查询早班护士
				JSONArray Order_nurse= trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
			                                                                                    null, section_id,"护士", null, null, morning_nurse_classesid);
				//早班护士
				if(Order_nurse.size()>0) {
					for (int j = 0; j < Order_nurse.size(); j++) {
						JSONObject obj2=new JSONObject();
						String  morning_nurse=Order_nurse.getJSONObject(j).getString("user_name");
						obj2.put("hushi", morning_nurse);
						json2.add( obj2);
					}
				}
				
				//护士---中班
				Integer middle_nurse_classesid=selectAll_nurse_arrange_classes.getJSONObject(1).getInteger("arrange_classsid");
				//System.out.println("查询排班班次---护士----"+morning_nurse_classesid);
				//查询中班护士
				JSONArray Order_nurse_middle= trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
			                                                                                    null, section_id,"护士", null, null, middle_nurse_classesid);
				//System.out.println("中班护士------------"+Order_nurse_middle);
				//中班护士
				if(Order_nurse_middle.size()>0) {
					for (int j = 0; j < Order_nurse_middle.size(); j++) {
						JSONObject obj4=new JSONObject();
						String  middle_nurse=Order_nurse_middle.getJSONObject(j).getString("user_name");
						obj4.put("hushi", middle_nurse);
						json4.add( obj4);
					}
				}
				
				//护士---晚班
				Integer night_nurse_classesid=selectAll_nurse_arrange_classes.getJSONObject(2).getInteger("arrange_classsid");
				//System.out.println("查询排班班次---护士----"+morning_nurse_classesid);
				//查询晚班护士
				JSONArray Order_nurse_night= trs.selectAllPresentOrderPeople(java.sql.Date.valueOf(curdate_format),
			                                                                                    null, section_id,"护士", null, null, night_nurse_classesid);
				//晚班护士
				if(Order_nurse_night.size()>0) {
					for (int j = 0; j < Order_nurse_night.size(); j++) {
						JSONObject obj6=new JSONObject();
						String  night_nurse=Order_nurse_night.getJSONObject(j).getString("user_name");
						obj6.put("hushi", night_nurse);
						json6.add( obj6);
					}
				}
				
				obj1.put("morning_doctor", json1);
				obj1.put("morning_nurse", json2);
				obj1.put("middle_doctor", json3);
				obj1.put("middle_nurse", json4);
				obj1.put("night_doctor", json5);
				obj1.put("night_nurse", json6);
				json.add(obj1);
			}
			//System.out.println("加入医生早班人员--——"+json);
			 return json;
			 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
		
	
	//根据排班科室查出当天【早班】排班人员
	@PostMapping(value="Present-MorningOrderPeople")
	@ResponseBody
	 public JSONArray  selectAllPresentMorningOrderPeople(String orderclass_time,String sectionname,String rolename,String arrangetime) {
 		    JSONArray selectAllPresentOrderPeople = null;
			try {
				selectAllPresentOrderPeople = trs.selectAllPresentMorningOrderPeople(orderclass_time,sectionname,rolename,arrangetime);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		  return selectAllPresentOrderPeople;
	 }
	
    	//根据排班科室查出当天【中班】排班人员
		@PostMapping(value="Present-MiddleOrderPeople")
		@ResponseBody
		 public JSONArray  selectAllPresentMiddleOrderPeople(String  orderclass_time,String sectionname,String rolename,String arrangetime) {
		    JSONArray selectAllPresentOrderPeople = null;
			try {
				selectAllPresentOrderPeople = trs.selectAllPresentMiddleOrderPeople(orderclass_time,sectionname,rolename,arrangetime);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			 return selectAllPresentOrderPeople;
		 }
	
		//根据排班科室查出当天【晚班】排班人员
		@PostMapping(value="Present-NightOrderPeople")
		@ResponseBody
		 public JSONArray  selectAllPresentNightOrderPeople(String  orderclass_time,String sectionname,String rolename,String arrangetime) {
			   JSONArray selectAllPresentOrderPeople = null;
				try {
					selectAllPresentOrderPeople = trs.selectAllPresentNightOrderPeople(orderclass_time, sectionname,rolename,arrangetime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
			  return selectAllPresentOrderPeople;
		 }	
		
		//排班科室初始化
		@RequestMapping("init-arrangesection")
		@ResponseBody
		public JSONArray initsection() {
			return trs.selectUserSectionArrange();
		}
		
		//科室下面对应人员初始化
		@RequestMapping("init-arrangeuser")
		@ResponseBody
		public JSONArray inituserdoctor(Integer sid,String role_name) {
			return trs.selectAllsectionPeople(sid,role_name);
		}
		
		//新增排班人员判断
		@RequestMapping("if-userArrange")
		@ResponseBody
		public String  ifUserArrange(Integer users_section,Integer  user_id,String order_datetime,String starEndtime) {
			System.out.println("cc排班时间段："+starEndtime);
	    	System.out.println("cc排班users_section："+users_section);
	     	System.out.println("cc排班ren ："+user_id);
	    	System.out.println("cc排班日期 ："+order_datetime);
			
	    	/*String order_startime=starEndtime.substring(0, 5);
	    	String startime=order_startime+":00";
	    	String order_endtime=starEndtime.substring(6,11);
	    	String endtime=order_endtime+":00";*/
			//如果新增排班的人=已经排班的人&& 新增科室=已经排班的科室 && 当前新增排班=当前已经排班的日期 && 新增排班的时间段=已经排班的时间段
			JSONArray selectAllPresentOrderPeople =  trs.IfOrderPeople(java.sql.Date.valueOf(order_datetime),users_section,user_id,Integer.valueOf(starEndtime)); 
			//查询到数据----出现提示框
			if(selectAllPresentOrderPeople.size()>0) {
				for (Object s : selectAllPresentOrderPeople) {
					System.out.println("存在排班------"+s);
				}
				Integer orderclass_id=selectAllPresentOrderPeople.getJSONObject(0).getInteger("orderclass_id");
			    return "{\"orderclass_id\":\""+orderclass_id+"\"}";
			    
			}else{
				 System.out.println("不存在相同排班");
				 return "2";
			}
		}
		
		//多人新增排班
	   @PostMapping(value="addorder_class")
	   @ResponseBody
	   public String addMang_Order_class(OrderClassVo arrangeclassvo) {
			  try {
				//新增排班
				  trs.addMang_Order_class(arrangeclassvo);
				  return "1";
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "2";
			}
	  }
	   
	   //修改排班班次
	   @PostMapping(value="update-arrangeClass")
	   @ResponseBody
	    public String updateArrangeClass(String orderclass_time,Integer arrangeclass_id,Integer section_id,Integer user_id,Integer old_arrangeclass_id,String old_arrange_classTime) {
	        System.out.println("排班班次："+arrangeclass_id+"--------old_arrangeclass_id:"+old_arrangeclass_id); 
	        System.out.println("排班日期："+orderclass_time); 
	        System.out.println("排班section_id："+section_id); 
	        System.out.println("排班user_id："+user_id); 
	       
		   try {
			   //查询到排班记录id---用于修改
				JSONArray selectAllPresentOrderPeople =  trs.IfOrderPeople(java.sql.Date.valueOf(old_arrange_classTime),section_id,user_id,old_arrangeclass_id); 
				Integer orderclass_id=selectAllPresentOrderPeople.getJSONObject(0).getInteger("orderclass_id");
				System.out.println("排班主键："+orderclass_id);
				
				trs.updateOrderclass(arrangeclass_id,java.sql.Date.valueOf(orderclass_time), orderclass_id);
	        	 return "1";
			} catch (Exception e) {
				 e.printStackTrace();
				 return "2";
			}
		}
	   
	   //排班班次初始化
	   @PostMapping(value="init_arrange_classes")
	   @ResponseBody
	   public String  init_arrange_classes() {
		   JSONArray init_arrange_classes = trs.init_arrange_classes(null);
		   	
		   return init_arrange_classes.toJSONString();
	   }
	   
	   //排班新增的弹框权限控制
	   @PostMapping(value="If-arrangeAdd")
	   @ResponseBody
	   public String IfarrangeAdd(HttpSession session){
	      	 //获取登录人
		     User user = (User)session.getAttribute("user");	
		     System.out.println("排班---直接获取登录人id："+user.getUserId());
		     //根据登录人的id查出登录人的角色
		     JSONArray selectLookpeople = ccs.selectLookDoctorBysid(null, user.getUserId());
		     System.out.println(selectLookpeople.size()+"排班------------根据登录人的id查出登录人的角色:"+selectLookpeople.getJSONObject(0).getString("role_name"));
	         //根据登录人的角色进行判断
		     String rolename = selectLookpeople.getJSONObject(0).getString("role_name");
		     System.out.println("排班---登录人的角色："+rolename);
		     //登录人为高级领导人：院长或是副院长
		     if(rolename.equals("院长") || rolename.equals("副院长")) {
		    	 return "1";
		     }
		     return "0";
	   }

	//挂号急诊选中判断
   @PostMapping(value="If-emergency")
   @ResponseBody 
	public String Ifemergency(String systimes){
	   JSONArray selectarrange_time = trs.selectarrange_time();
	   String arrange_endclassses = selectarrange_time.getJSONObject(0).getString("arrange_endclassses");
	   //System.out.println("arrange_endclassses：12222222222222222-----" + arrange_endclassses);
	   //获取系统时间
	    Date d = new Date();
		System.out.println(d);
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		String dateNowStr = sdf.format(d);
		System.out.println("格式化后的日期：" + dateNowStr);
	   //系统时间>医生上班时间
	   if(dateNowStr.compareTo(arrange_endclassses)>0) {
		   //System.out.println("系统时间>医生上班时间");
		   return "1";
	   }
	   return "2";
   }
   
   //根据人员初始化排班班次combbox-----开始时间
   @PostMapping(value="init-arrangeclasses")
   @ResponseBody 
	public JSONArray  initArrangeclasses(Integer userid){
	   //根据用户id查到角色
	   JSONArray selectuser_role = trs.selectuser_role(userid);
	   JSONArray selectarrange_classes = null;
	   for (int i = 0; i < selectuser_role.size(); i++) {
		   String arrange_role=selectuser_role.getJSONObject(i).getString("role_name");
		   //根据角色查到排班班次
		   selectarrange_classes = trs.selectarrange_classes(arrange_role);
		 /*  for (Object object : selectarrange_classes) {
			  System.out.println("根据人员初始化排班班次--------:"+object);
		    }*/
		 }
	    if(selectarrange_classes.size()>0) {
	    	  //System.out.println("selectarrange_classes.size()>0");
	    	  return selectarrange_classes;
	    }else {
	    	//System.out.println("selectarrange_classes.size()<0");
	    	return null;
	    }
   }
   
   //根据开始排班班次combbox---结束排班班次
   @PostMapping(value="init-arrangeclasses-endclass")
   @ResponseBody 
	public JSONArray  arrangeclasses_endclass(Integer arrangeclass_ids){
	   //System.out.println("arrangeclass_ids-------:"+arrangeclass_ids);
	   JSONArray arrangeclasses_endclass = trs.arrangeclasses_endclass(arrangeclass_ids);
	    if(arrangeclasses_endclass.size()>0) {
	    	  //System.out.println("结束时间查到了！！！");
	    	  return arrangeclasses_endclass;
	    }else {
	    	//System.out.println("结束时间没有查到了！！！");
	    	return null;
	    }
   }
   
   //根据角色查【早班】班次--表格初始化
   @PostMapping(value="init-roleArrange")
   @ResponseBody 
	public JSONArray  initRoleArrange(String  rolename){
	   System.out.println("rolename1234567:"+rolename);
	    JSONArray selectarrange_classes = trs.selectarrange_classes(rolename);
	    for (Object t : selectarrange_classes) {
	    	System.out.println("根据角色查【早班】班次--表格初始化----:"+t);
		}
	 /*   String end_starclassses = selectarrange_classes.getJSONObject(0).getString("arrange_starclassses");
		String end_endclassses = selectarrange_classes.getJSONObject(0).getString("arrange_endclassses");
		
		JSONArray morning=new JSONArray();
		morning.add(0, end_starclassses);
		morning.add(1, end_endclassses);*/
	    return selectarrange_classes;
   }
	
	//门诊医疗卡管理页面
	@RequestMapping("medical-card")
	public String outpatientregist(Model  m , Integer sectionid){
		 //生成随机数
		int cliniccards=(int)((Math.random()*4+1)*100000);
		m.addAttribute("cliniccard", cliniccards);
		//System.out.println("随机医疗卡："+cliniccards);
		return "out-medicalcard";
	}
	
	//门诊挂号管理页面
	@RequestMapping("out-registrationoffice")
	public String registrationoffice(Model model,Integer sectionid){
		/* List<Section> selectAllsection = ss.selectAllsection(sectionid);
		model.addAttribute("sectionlist", selectAllsection);*/
		return "out-registrationoffice";
	}
	 
	//医生看诊
	@RequestMapping("look-doctor")
	public String lookdoctor(){
		
		return "out-lookdoctor";
		
	}
	
	//门诊收费
	@RequestMapping("out-charge-management")
	public String outchargemanagement(){
		
		return "out-chargemanagement";
	}
	
	//护士工作站
	@RequestMapping("out-nurse")
	public String outnurse(){
		
		return "out-nurse";
	}
	
	//医疗卡新增
	@PostMapping(value="add-clinic")
	public void addclinic( String clinicName,String cliniccardId, String clinicIdnumber,Integer clinicAge,
												String clinicAddress,String clinicTel,String clinicHandlename,
												BigDecimal clinicRemainmoney, String clinicSex) {
	        	System.out.println("医疗卡号："+cliniccardId);
	        	System.out.println("名字："+clinicName);
	        	System.out.println("年龄："+clinicAge);
	        	System.out.println("性别："+clinicSex);
	        	System.out.println("电话："+clinicTel);
	        	System.out.println("地址："+clinicAddress);

		        ccs.addcliniccard(cliniccardId, clinicName, clinicIdnumber, clinicAge, clinicSex, clinicTel, clinicAddress, clinicHandlename,new BigDecimal(0),0);
	}
	
	//医疗卡管理初始化表格数据
	@PostMapping(value="selectAll-clinic")
	@ResponseBody
	public Map<String,Object>  selectAllclinic(
			@RequestParam("page")int page,
			@RequestParam("rows")int rows,String cliniccardid,String clinicname){
		//进行分页
		 Page<Object> pg = PageHelper.startPage(page, rows);
		 List<ClinicCard>  list = ccs.selectAllbycardid(0,cliniccardid,clinicname,null);
		
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		System.out.println("1:"+pg.getTotal());
		map.put("rows", list);//封装当前页的内容
		System.out.println("2:"+ list.size());
		return map;
	}
	
	
	//医疗卡充值----首先新增充值记录表----然后改变医疗卡用户的剩余金额
	@PostMapping(value="add-rechange")
	@ResponseBody
	 public void addrechange(Integer clinic_id,Integer rechange_type, BigDecimal rechange_money) {
		     rechange_type=0;
		    System.out.println("医疗卡主键："+clinic_id);
		    System.out.println("金额："+rechange_money);
		    res.addrechange(clinic_id, rechange_type, rechange_money);
			ccs.updatemoney(rechange_money, clinic_id);
	 }
	
	
	
	//挂号根据医疗卡号查询
	@PostMapping("find-cliniccardid")
	@ResponseBody
	public String findcliniccardid(String cliniccardid){
		 List<ClinicCard>  lists = ccs.selectAllbycardid(0,cliniccardid,null,null);
		JSONObject json = new JSONObject();
		json.put("cliniccardid",lists);
		return json.toJSONString();
	}
	
	//挂号科室初始化
	@RequestMapping("init-section")
	@ResponseBody
	public List<Section> initsection(Integer sectionid) {
		return ss.selectAllsection(sectionid,"门诊");
		
	}
	
	//挂号类型初始化
	@RequestMapping("init-regstrtype")
	@ResponseBody
	public List<RegistrType> initregstrtype(Integer retypeid,String retypename) {
		return regts.selectAllregtype(retypeid,retypename);
		
	}
	
	//挂号医疗卡充值判断余额是否充足
	@PostMapping(value="init-money")
	@ResponseBody
	public String   initmoney(String yumoney,Integer regstrtypeid,Integer sectionid) {
		 //根据挂号类型id查询挂号的价格
		  List<RegistrType> selectAllregtype = regts.selectAllregtype(regstrtypeid, null);
		  Integer rtype=selectAllregtype.get(0).getRegistrtypeId();
		  System.out.println("挂号类型:"+selectAllregtype.get(0).getRegistrtypeName());
		  System.out.println("挂号价格:"+selectAllregtype.get(0).getRegistrtypePrice());
		  //看诊价格--根据
		  List<Section> selectAllsection = ss.selectAllsection(sectionid,null);
		  System.out.println("科室价格11:"+sectionid); 
		  System.out.println("科室价格:"+selectAllsection.get(0).getSectionPrice()); 
		  //获取余额
		  System.out.println("余额:"+yumoney);
		   //如果是门诊
		  if(Integer.valueOf(rtype)==1) {
			  System.out.println("余额门诊！！！！！！！！！！！");
			  //挂号科室的钱----看诊费+挂号类型费用
			  BigDecimal tmoney=selectAllsection.get(0).getSectionPrice().add(selectAllregtype.get(0).getRegistrtypePrice());
			  if(tmoney.compareTo(new BigDecimal(yumoney))==1) {
				  System.out.println("余额不足-------门诊");
				    return  "1";
			  }
		  }else{
			  BigDecimal tmoney=selectAllsection.get(0).getSectionPrice().add(selectAllregtype.get(0).getRegistrtypePrice());
			  if(tmoney.compareTo(new BigDecimal(yumoney))==1) {
				   System.out.println("余额不足-------急诊");
				    return "2";
			  }
		  }
           return "3";
	}
	
	//挂号新增---医疗卡支付要新增医疗卡记录
	@PostMapping(value="add-registrfrom")
	public void addregistrfrom( String cliniccardid,String sectionname, Integer registrformType,
															Integer registrfrommoneytype,String registrfrom_name,String retypename) {
		regs.addregistrfrom(cliniccardid, sectionname, registrformType, registrfrommoneytype, registrfrom_name, retypename);
	}
	
	//初始化挂号
	@PostMapping(value="selectAll-registr")
	@ResponseBody
	public Map<String,Object>  selectAllregistr(
			@RequestParam("page")int page,
			@RequestParam("rows")int rows,/*String cliniccardid*/String clinicname){
		//进行分页
		 Page<Object> pg = PageHelper.startPage(page, rows);
		 JSONArray array = regs.selectRegistrFromAll(clinicname);
		 for (Object o : array) {
			System.out.println(o.toString());
		}
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", array);//封装当前页的内容
		return map;
	}
	
		//初始化药品 
		@PostMapping("findall-outdrug")
		@ResponseBody
		public  Map<String,Object>  findalldrug(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows, String drugname){

				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray findAllDrug = drugroomservice.select_OutPatientDrug_record(drugname);
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", findAllDrug);//封装当前页的内容

				return map;
				
		}
		
		//初始化体检项目
		@RequestMapping("findall-outhealthproject")
		@ResponseBody
		public  Map<String,Object>  findallhealproject(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows,String projectname){

				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray findhealproject = apps.selectHealBysid(projectname);
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", findhealproject);//封装当前页的内容

				return map;
				
		}
		
		//初始化医疗项目
		@PostMapping("select-hospitalhproject")
		@ResponseBody
		public  Map<String,Object>  selecthospitalhproject(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows, String hprojectname){

				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray findhosproject = hs.selectHospitalprojectByname(hprojectname);
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", findhosproject);//封装当前页的内容

				return map;
				
		}
		
		//分诊管理
		@RequestMapping("out-triage")
		public String outriage(){
			
			return "out-triage";
		}
		
		//分诊初始化表格
		@PostMapping("init-triage")
		@ResponseBody
		public  Map<String,Object>  inittriage(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows, String clinicname,HttpSession session){
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray findalltriage= trs.selectAlltriage(0,clinicname);
				
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", findalltriage);//封装当前页的内容

				return map;
		}
		
		//分诊的医生下拉框
		@RequestMapping("init-docter")
		@ResponseBody
		public  JSONArray initdocter(@RequestParam("sectionname")String sectionname) {
		      //System.out.println("------科室名称---------："+sectionname);
			  //根据挂号科室查出科室里排班的所有医生
			  JSONArray doc = trs.selectAlldoctor(sectionname);
			   return doc;     
		}
	
		//获取选中分诊的挂号id
		@PostMapping(value="get-registr")
		@ResponseBody
		 public  String  inittriage(Model  m,String arrays,String docters) {
			System.out.println("获取到的挂号id："+arrays);
		    m.addAttribute("doctersarray", docters);
		    m.addAttribute("resgistrarray", arrays);
			System.out.println("获取到的分诊医生名字："+docters);
				if(!("").equals(arrays)) {
					String arrs []=arrays.split(",");
					String arrdoc []=docters.split(",");
					for (int i = 0; i < arrs.length; i++) {
						System.out.println("遍历获取到的挂号id："+arrs[i]);
						//分诊之后改已经分诊---将对应医生填写
					   for (int j = 0; j < arrdoc.length; j++) {
						   if(i==j) {
							   System.out.println("挂号医生："+arrdoc[j]);
								regs.updatetriagestate(Integer.parseInt(arrs[i]),1,arrdoc[j]);
						   }
					    }
					}
					return "1";
				}
				return "2";
		}
		
		//看诊医疗卡查询
		@PostMapping("lookdoctor-cliniccardid")
		@ResponseBody
		public  Map<String, Object> lookdoctorcliniccardid(@RequestParam("page")int page,
				  																						  @RequestParam("rows")int rows,
				  																						  HttpSession session, String cliniccardid,
				  																						  Integer registr_id){
		  Map<String, Object> lookdoctorcliniccardid = lookservice.lookdoctorcliniccardid(page, rows, session, cliniccardid, registr_id);
		  		    			 
		  return 	lookdoctorcliniccardid;  
		}
		
		//住院申请
		@PostMapping(value="apply-hospital")
		@ResponseBody
		public JSONArray applyhospital(Integer lid){
			     //根据看诊号申请住院
				JSONArray selectApplyhospital = ccs.selectApplyhospital(lid);
			     return selectApplyhospital;
		}
		
		//住院申请新增
		@RequestMapping(value="add-applyHospital")
		public void addapplyHospital(Integer quicklookid,String applyuser) {
			System.out.println("---id:"+quicklookid);
			System.out.println("---id----:"+applyuser);
			applys.AddApply(quicklookid, applyuser);
		}

		
	     //看诊新增
		@PostMapping(value="add-lookillness")
		@ResponseBody
		public String addlookillness(HttpSession session,AdviceVo advvo) {
						try {
							lookservice.savelookillness(advvo);
							LookIllness illness = lookservice.selectBylookillness();
							//点击保存看诊传看诊号过去
							Integer illnessid=illness.getLookillnessId();
							System.out.println("新增完看诊id："+illnessid);
							return "{\"lookid\":\""+illnessid+"\"}";
						} catch (Exception e) {
							e.printStackTrace();
							return "看诊新增失败！！！";
						}
			
		}
		
		//处方管理
		@PostMapping(value="add-docdrug")
		@ResponseBody
		public String addcliniccardId(HttpSession session , String lookdoctor_results,
															 AdviceVo advvo) {
					//新增看诊----医嘱表--医嘱详情表
					try {
						lookservice.saveDocter(advvo);
						return "开立成功";
					} catch (Exception e) {
						e.printStackTrace();
						return "失败";
					}
		}
		
		//开体检项目
		//开立体检（新增体检表，医疗卡表，项目表）
		@PostMapping("outadd-health")
		@ResponseBody
		public String OutAddHealth(Integer look_id,String project_arr,String totalmoney) {
			try {
				lookservice.OutAddHealth(look_id, project_arr, totalmoney);
				return "开体检项目成功";
			} catch (Exception e) {
				e.printStackTrace();
				return "开体检项目失败";
			}
		}
		
	 	//开医疗项目
		@PostMapping("save-Hosproject")
		@ResponseBody
     	public String saveHosproject(HospitalProjectVo hosvo) {
		     		try {
						lookservice.saveHosproject(hosvo);
						return "医疗项目成功";
					} catch (Exception e) {
						e.printStackTrace();
						return "医疗项目失败";
					}
     	}
		
		//门诊收费看诊号查询
		@PostMapping("chargemoney-lookillnessid")
		@ResponseBody
		public Map<String, Object>  lookdoctorlookillnessid(@RequestParam("page")int page,
																											@RequestParam("rows")int rows) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray money= ccs.chargemoneylookillnessid(2, null);
			for (Object object : money) {
				System.out.println("收费初始化信息------------："+object);
			}
			
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", money);//封装当前页的内容
 
			return map;
			
		}
		
		//药物收费
		@PostMapping(value="select-drugMoney")
		@ResponseBody
		public Map<String, Object> selectdrugMoney(@RequestParam("page")int page,
																								@RequestParam("rows")int rows, Integer lookids) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray drugmoney= ccs.selectdrugMoney(0,lookids);
			
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", drugmoney);//封装当前页的内容
 
			return map;
		}
		
		//体检收费
		@PostMapping(value="select-healMoney")
		@ResponseBody
		public Map<String, Object> selecthealthMoney(@RequestParam("page")int page,
																								   @RequestParam("rows")int rows, Integer lid) {
			
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray healthmoney= ccs.selecthealMoney(lid);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", healthmoney);//封装当前页的内容
 
			return map;
		}
		
		//自主体检医疗卡人员信息
		@PostMapping(value="select-healthclinicid")
		@ResponseBody
		public JSONArray selecthealthclinicid() {
			
			JSONArray healthmoneys= ccs.selectselfhealthClinic();
			
			return healthmoneys;
		}
		
		//自主体检收费
		@PostMapping(value="select-selfhealthmoney")
		@ResponseBody
		public Map<String, Object>  selectselfhealthmoney(@RequestParam("page")int page,
																					   @RequestParam("rows")int rows,String cid) {
			
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray healthmoneys= ccs.selectselfhealthmoney(cid);
			/*System.out.println("医疗卡号：-------------自主体检收费：------"+cid);
			for (Object object : healthmoneys) {
				System.out.println("-自主体检收费：------"+object);
			}*/
			
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", healthmoneys);//封装当前页的内容
 
			return map;
		}
		
		//医疗项目收费
		@PostMapping(value="select-HosptialMoney")
		@ResponseBody
		public Map<String, Object>  selectHosptialMoney(@RequestParam("page")int page,
																					                       @RequestParam("rows")int rows,Integer llid) {
			
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray hospitalmoneys= ccs.selectHosptialMoney(llid);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", hospitalmoneys);//封装当前页的内容
 
			return map;
		}
		
		//药物收费---新增
		@PostMapping(value="add-drugmoney")
		@ResponseBody
		 public String adddrugmoney(ChargemoneyVo chvo) {
			try {
				chs.saveDrugmoney(chvo);
				return "药物收费成功";
			} catch (Exception e) {
				e.printStackTrace();
				return "药物收费失败";
			}
		 }
		
		//医疗项目收费
		@PostMapping(value="add-HospitalProjectmoney")
		@ResponseBody
		public String saveHospitalProjectmoney(ChargemoneyVo chvo,Integer hosplookid) {
			try {
				 chs.saveHospitalProjectmoney(chvo);
				//收费成功----修改医疗项目收费状态---0
				 chs.updateHosProjectMoneytype(0, hosplookid);
				return "医疗项目收费成功";
			} catch (Exception e) {
				e.printStackTrace();
				return "医疗项目收费失败";
			}
		}
		
		//体检收费
		@PostMapping("add-outhealthMoney")
		@ResponseBody
		public String addouthealthMoney(Integer look_id,String healthno_arr,String totalmoney,String chargename) {
			try {    
			   chs.addouthealthMoney(look_id, healthno_arr, totalmoney, chargename);
			   return "体检项目收费成功";
			} catch (Exception e) {
				e.printStackTrace();
				return "体检项目收费失败";
			}
			
		}
		
		//收费项目初始化
		@PostMapping("select-Money")
		@ResponseBody
		public JSONArray selectMoney(Integer lookid){
			JSONArray selectMoney = chs.selectMoney(lookid);
			 
			    return selectMoney;
		}
		
		//叫号
		@PostMapping("lookdoctor-callNumber")
		@ResponseBody
		public  Map<String, Object> lookdoctorcallNumber(@RequestParam("page")int page,
				  																						   @RequestParam("rows")int rows,
				  																						   HttpSession session, String cliniccardid,
				  																						   Integer registr_id){
			   try {
			    	     Map<String, Object> lookdoctorcliniccardid = lookservice.lookdoctorcallNumber(page,rows,session, cliniccardid, registr_id);
				    	 return lookdoctorcliniccardid;
				} catch (Exception e) {
						e.printStackTrace();
					    return null;
				}
		}
		
		//修改加号
		@PostMapping("update-callstate")
		@ResponseBody
		public void  updatecallstate( Integer regid) {
			 //双击叫号完之后改变叫号的状态
			 regs.updatecallstate(regid, 1);
	    	   
		}
		
		
		@PostMapping("select-NoChargePeople")
		@ResponseBody
		public Map<String, Object>  selectNoChargePeople(@RequestParam("page")int page,
																											@RequestParam("rows")int rows) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray nomoney= chs.selectNoChargePeople();
	
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", nomoney);//封装当前页的内容
 
			return map;
			
		}
		
		//自主体检收费
		@PostMapping(value="add-SelfhealthMoney")
		@ResponseBody
	   	public String addSelfhealthMoney(String appo_no_arr,String totalmoney,String chargename) {
			System.out.println("appo_no_arr:"+appo_no_arr);
	   		try {    
	   			   chs.addSelfhealthMoney(appo_no_arr, totalmoney, chargename);
				   System.out.println("自主体检项目收费成功--------controller");
				   return "1";
				} catch (Exception e) {
					e.printStackTrace();
					return "2";
				}
	  }	
		
		//自主体检收费项目初始化
		@PostMapping(value="select-selfMoney")
		@ResponseBody
		public JSONArray selectMoney(String ccardid){
			JSONArray selectselfMoney = chs.selectSelfMoney(ccardid);
			for (Object object : selectselfMoney) {
				System.out.println("自主体检收费项目初始化:"+object);
			}
			    return selectselfMoney;
		}	
		
		//看诊修改
		@PostMapping(value="update-lookillness")
		@ResponseBody
		public String updatelookillness(Integer docadvice_id,Integer lookid,String lookinessReason,String lookinessResult,String docadviceConent){
		 try {
		    	 lookservice.UpdateLookillnessq(docadvice_id, lookid, lookinessReason, lookinessResult, docadviceConent);
                 return "医嘱看诊修改成功！！！";
			} catch (Exception e) {
				  e.printStackTrace();
				  return "医嘱看诊修改失败！！！";
			}
		       
		}	
		
		//根据挂号id查询看诊号
		@PostMapping("lookdoctor-redo")
		@ResponseBody
		public String  lookdoctorredo(Integer registr_id){
			  JSONArray selectByLookid = ccs.selectByLookid(registr_id);
			  /*Integer looksid = selectByLookid.getJSONObject(0).getInteger("lookillness_id");*/
			  System.out.println("registr_id:"+registr_id);
			  if(selectByLookid.size()>0) {
				  System.out.println("查到看诊号!!!!!!");
				  return selectByLookid.toJSONString();
			  }else {
				 System.out.println("没有查到看诊号!!!!!!!");
			  	 return "2";
			  }
		}
		
		//二次看诊新增医嘱详情
		@PostMapping(value="save-Docterredo")
		@ResponseBody
		public String saveDocterredo(AdviceVo advvo) {
			 try {
		    	 lookservice.saveDocterredo(advvo);
                 return "二次看诊成功！！！";
			} catch (Exception e) {
				  e.printStackTrace();
				  return "二次看诊失败！！！";
			}
		}
		
		//新增交易记录修改余额
		@PostMapping(value="add-chargeRechangeMoney")
		@ResponseBody
		 public String  addchargeRechangeMoney(Integer clinic_ids,BigDecimal rechange_money) {
			 //新增交易记录
			 try {
				    System.out.println("医疗卡主键："+clinic_ids+"-----支付金额："+rechange_money);
					 regs.addchargeRechangeMoney(clinic_ids, rechange_money);
					 return "医疗卡交易成功！！！";
				} catch (Exception e) {
					  e.printStackTrace();
					 return "医疗卡交易失败！！！";
				}
		 }
		
		//挂号打印票据
		@PostMapping(value="Registr-Ticket")
		@ResponseBody
		 public JSONArray RegistrTicket() {
			JSONArray registrTicket = regs.RegistrTicket();
			int regwaternumber=(int)((Math.random()*5+1)*1000000);
			  JSONObject o =  (JSONObject) registrTicket.get(0);
			  o.put("regwaternumber", regwaternumber);
			  for (Object t : registrTicket) {
				System.out.println("挂号打印票据:"+t);
			}
			return registrTicket;
		 }
		
		 //根据看诊号与收费类型查到药物收费单号
		@PostMapping(value="select-chargeMoneyNumber")
		@ResponseBody
		 public JSONArray selectchargeMoneyNumber(Integer look_number,String chargemoney_name) {
			JSONArray selectChargeMoneyid = chs.selectCMoneyid(chargemoney_name, look_number);
			if(selectChargeMoneyid.size()>0) {
				return selectChargeMoneyid;
			}
			return null;
		 }
		
		//病历本看诊记录
		@PostMapping(value="lookdoctor-sickrecord")
		@ResponseBody
		 public Map<String, Object> selectBylookrecord(@RequestParam("page")int page,
																									@RequestParam("rows")int rows,Integer clinic_card){
			 
			 if(clinic_card!=null) {
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray selectBylookrecord = ccs.selectBylookrecord(clinic_card,null);
				/*for (Object g : selectBylookrecord) {
					System.out.println("病历本看诊记录------------------"+g);
				}*/
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", selectBylookrecord);//封装当前页的内容
				
				return map;
		   }
		   return null;
		}
		
		 //病历本根据日期看诊记录
		@PostMapping(value="Searchlookdoctor-sickrecord")
		@ResponseBody
		 public Map<String, Object>SearchselectBylookrecord(@RequestParam("page")int page,
																									             @RequestParam("rows")int rows,
																									             Integer clinic_card,String lookdate){
			 if(clinic_card!=null &&lookdate!=null) {
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray selectBylookrecord = ccs.selectBylookrecord(clinic_card,java.sql.Date.valueOf(lookdate));
				for (Object g : selectBylookrecord) {
					System.out.println("病历本看诊记录------------------"+g);
				}
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", selectBylookrecord);//封装当前页的内容
				
				return map;
			 }
			 return null;
		}
		
		
		//病历本体检记录
		@PostMapping(value="lookdoctor-healthrecord")
		@ResponseBody
		 public Map<String, Object> selectByhealthrecord(@RequestParam("page")int page,
																									@RequestParam("rows")int rows,Integer clinic_card){
			 
			 if(clinic_card!=null) {
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray selectByhealthrecord = ccs.selectByhealthrecord(clinic_card, null);
				/*for (Object g : selectBylookrecord) {
					System.out.println("病历本看诊记录------------------"+g);
				}*/
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", selectByhealthrecord);//封装当前页的内容
				
				return map;
			  }
			    
			    return null;
		}
		
		//病历本体检记录日期查询
		@PostMapping(value="Searchlookdoctor-healthrecord")
		@ResponseBody
		 public Map<String, Object> SearchselectByhealthrecord(@RequestParam("page")int page,
																													  @RequestParam("rows")int rows,
																													  Integer clinic_card,String lookdate){
			    
			    if(lookdate!=null && clinic_card!=null) {
			    	//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					JSONArray selectByhealthrecord = ccs.selectByhealthrecord(clinic_card, java.sql.Date.valueOf(lookdate));
					/*for (Object g : selectBylookrecord) {
						System.out.println("病历本看诊记录------------------"+g);
					}*/
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", selectByhealthrecord);//封装当前页的内容
					
					return map;
			    }
			    
			    return null;
		}
		
		//自主体检收费--查询收费主键
		@PostMapping(value="select-chargeMoneyNumberself")
		@ResponseBody
		public JSONArray selectCMoneyidSelf(String  chargemoney_name,String  appo_no){
		 try {
			 	   //System.out.println("appo_no________"+appo_no);
			       String arr[] =appo_no.split(",");
					for(int i=0;i<arr.length;i++){
						 //System.out.println("456789oooooooooooo______"+arr[i]);
						JSONArray selectCMoneyidSelf = chs.selectCMoneyidSelf(chargemoney_name,Integer.valueOf(arr[i]) );
						if(selectCMoneyidSelf.size()>0) {
						   return selectCMoneyidSelf;
						}
					}  
			   
			} catch (Exception e) {
				  e.printStackTrace();
				 
			}
		return null;
		       
		}
		
		@PostMapping(value="check-idcard")
		@ResponseBody
		public String IDcard(String clinic_idnumber) {
			//System.out.println("clinic_idnumber:"+clinic_idnumber);
			try {
				if(!clinic_idnumber.equals("")) {
					List<ClinicCard> selectAllbycardid = ccs.selectAllbycardid(null, null, null,clinic_idnumber);
					if(selectAllbycardid.size()>0) {
						return "1";
					}else {
					    return "2";
					}
				}
				return null;
			} catch (Exception e) {
				return null;
			}
		}
		
}
